using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using Microsoft.Practices.RecipeFramework.Library;

namespace PrismFactory.SoftwareFactory.Extensions.Actions.VisualStudio
{
    public class CreateProjectFolderAction : ConfigurableAction
    {
        private ProjectItem createdItem;

        public CreateProjectFolderAction()
        {
            CreateFolder = false;
        }

        [Input()]
        public bool CreateFolder { get; set; }

        [Input(Required = true)]
        public string FolderName { get; set; }

        [Input(Required = true)]
        public ProjectItems TargetCollection { get; set; }

        [Output()]
        public ProjectItems FolderCollection { get; set; }

        public override void Execute()
        {
            if (CreateFolder)
            {
                createdItem = DteHelper.FindItemByName(TargetCollection, FolderName, false);
                if (createdItem == null)
                {
                    createdItem = TargetCollection.AddFolder(FolderName, "{6BB5F8EF-4483-11D3-8BCF-00C04F8EC28C}");
                }
                FolderCollection = createdItem.ProjectItems;

            }
            else
            {
                FolderCollection = TargetCollection;
            }
        }

        public override void Undo()
        {
            //if (createdItem != null)
            //5    createdItem.Delete();
        }
    }
}